package com.zr.d_c.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zr.d_c.model.Dish;
import com.zr.d_c.model.User;
import com.zr.d_c.service.DishService;
import com.zr.d_c.service.SellerService;
import com.zr.d_c.serviceimpl.DishServiceImpl;
import com.zr.d_c.serviceimpl.SellerServiceImpl;
/**
 * 更新菜品信息
 * @author Administrator
 *
 */
public class UpdateDishController extends HttpServlet {
	DishService dishService = new DishServiceImpl();
	SellerService sellerService = new SellerServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		req.setCharacterEncoding("utf8");
		resp.setCharacterEncoding("utf8");
		HttpSession session = req.getSession();
		User u = (User) session.getAttribute("currentUser");
		int uid = u.getUid();
		int sid = sellerService.getSellerSidByUid(uid);
		PrintWriter pw = resp.getWriter();
		int did = Integer.parseInt(req.getParameter("did"));
		String dname = req.getParameter("dname");
		int dnum = Integer.parseInt(req.getParameter("dnum"));
		int dprice = Integer.parseInt(req.getParameter("dprice"));
		Dish dish = new Dish(did,dname, dnum, dprice);
		if(dishService.modifyDish(dish,sid)){
			pw.write("1");
		}else{
			pw.write("0");
		}
		
		
	}
}
